package com.xiaoma.thread.wait;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import org.junit.Test;


public class TestBlockedSocketState {

  @Test
  public void testBlockedSocketState() throws Exception {
    Thread serverThread = new Thread(new Runnable() {
      @Override
      public void run() {
        ServerSocket serverSocket = null;
        try {
          serverSocket = new ServerSocket(10086);
          while (true) {
            // 阻塞的accept方法
            Socket socket = serverSocket.accept();
            // TODO
          }
        } catch (IOException e) {
          e.printStackTrace();
        } finally {
          try {
            serverSocket.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      }
    }, "socket线程"); // 线程的名字
    serverThread.start();

    // 确保run已经得到执行
    Thread.sleep(500);

    // 状态为RUNNABLE
    System.out.println((serverThread.getState()).equals(Thread.State.RUNNABLE));

  }
}
